<template>
	<view :class="isShowEmptyData ? 'content-empty' : 'content'">
		<view class="serve">
			<view v-if="isShowServeInfo" class="serve-item">
				<view class="header header-more">
					<view class="horizontal">
						<view class="line"></view>
						<view class="serve-item-title">联系方式</view>
					</view>
					<view class="serve-close" @click="isShowServeInfo = false">
						<image src="../../static/close_icon2.png" mode="widthFix"></image>
					</view>
				</view>
				<view class="dividing-line"></view>
				<view class="serve-item-list">
					<view class="serve-item-list">
						<view class="serve-image">
							<image src="../../static/wechat.png" mode="widthFix"></image>
						</view>
						<view class="serve-title">14865978215</view>
					</view>
					<view class="serve-item-list">
						<view class="serve-image">
							<image src="../../static/phone.png" mode="widthFix"></image>
						</view>
						<view class="serve-title">15948753264</view>
					</view>
					<view class="serve-item-list">
						<view class="serve-image">
							<image src="../../static/hotline.png" mode="widthFix"></image>
						</view>
						<view class="serve-title">400-6369-798</view>
					</view>
				</view>
			</view>
			<view v-else class="serve-image" @click="isShowServeInfo = true">
				<image src="../../static/serve.png" mode="widthFix"></image>
			</view>
		</view>

		<view v-if="isShowDialog" class="index_dialog">
			<image class="dialog_banner" src="../../static/dialog_banner.png" mode="widthFix"></image>
			<image class="dialog_close" src="../../static/close_icon.png" mode="widthFix" @click="isShowDialog = false">
			</image>
		</view>

		<view class="empty-data" v-if="isShowEmptyData">
			<view class="empty-content">
				<image class="empty-image" src="../../static/empty_data.png" mode="widthFix"></image>
				<view class="empty-text">暂无数据</view>
			</view>
		</view>
		<view v-else>
			<image src="../../static/home_banner.png" mode="widthFix"></image>
			<view class="menu-list">
				<view class="menu-item" @click="openBuilderPage">
					<view class="menu-image">
						<image src="../../static/loupan_menu.png" mode="widthFix"></image>
					</view>
					<view class="menu-text"><text>热改楼盘</text></view>
				</view>
				<view class="menu-item" @click="openComboPage">
					<view class="menu-image">
						<image src="../../static/linbao_menu.png" mode="widthFix"></image>
					</view>
					<view class="menu-text"><text>拎包入住</text></view>
				</view>
				<view class="menu-item" @click="openConstructionPage">
					<view class="menu-image">
						<image src="../../static/gongdi_menu.png" mode="widthFix"></image>
					</view>
					<view class="menu-text"><text>工地实景</text></view>
				</view>
				<view class="menu-item">
					<view class="menu-image">
						<image src="../../static/baojie_menu.png" mode="widthFix"></image>
					</view>
					<view class="menu-text"><text>保洁阿姨</text></view>
				</view>
			</view>
			<view>
				<view class="select">
					<view class="header header-more">
						<view class="horizontal">
							<view class="line"></view>
							<view class="select-header">热改楼盘</view>
						</view>
						<view class="horizontal" @click="openBuilderPage">
							<view class="more-text">更多</view>
							<view class="more-icon"></view>
						</view>
					</view>
					<view class="select-list">
						<view class="select-item" @click="openBuilderDetails(item.id)"
							v-for="(item, index) in buildList" :key="index">
							<view class="select-image">
								<image :src="item.thumb" mode="scaleToFill"></image>
							</view>
							<view class="select-mark">
								<view class="select-title">{{ item.name }}</view>
								<view class="select-content">{{ item.model.name }}/{{ item.style.name }}</view>
							</view>
						</view>
					</view>
				</view>

				<view class="select">
					<view class="header header-more">
						<view class="horizontal">
							<view class="line"></view>
							<view class="select-header">拎包入住</view>
						</view>
						<view class="horizontal" @click="openComboPage">
							<view class="more-text">更多</view>
							<view class="more-icon"></view>
						</view>
					</view>
					<view class="select-list">
						<view class="select-item" v-for="(item, index) in comboList" :key="index">
							<view class="select-image">
								<image :src="item.thumb" mode="scaleToFill"></image>
							</view>
							<view class="select-mark">
								<view class="select-title">{{ item.name }}</view>
								<view class="select-content">{{ item.model }}m²</view>
								<view class="select-content">{{ item.desc_str }}</view>
							</view>
						</view>
					</view>
				</view>

				<view class="select">
					<view class="header header-more">
						<view class="horizontal">
							<view class="line"></view>
							<view class="select-header">工地实景</view>
						</view>
						<view class="horizontal" @click="openConstructionPage">
							<view class="more-text">更多</view>
							<view class="more-icon"></view>
						</view>
					</view>
					<view class="select-list">
						<view @click="openConstructionDetails(item.id)" class="select-item"
							style="width: 520rpx;height: 312rpx;" v-for="(item, index) in constructionList"
							:key="index">
							<view class="select-image" style="width: 520rpx;height: 312rpx;">
								<image :src="item.thumb" mode="widthFix"></image>
							</view>
							<view class="select-mark" style="width: 520rpx;">
								<view class="select-title" style="text-align: center;">{{ item.name }}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isShowDialog: true,
				isShowServeInfo: false,
				isShowEmptyData: false,
				buildList: [],
				comboList: [],
				constructionList: []
			};
		},
		onLoad() {
			uni.request({
				url: 'https://baiyi.kent.work/api/v1/system/getIndexData',
				method: 'GET',
				success: res => {
					if (res.data.code == 200) {
						this.isShowEmptyData = false;
						this.buildList = res.data.data.buildList;
						this.comboList = res.data.data.comboList;
						this.constructionList = res.data.data.constructionList;
					} else {
						this.isShowEmptyData = true;
					}
				},
				fail: e => {
					this.isShowEmptyData = true;
				}
			});
		},
		methods: {
			openBuilderPage() {
				uni.navigateTo({
					url: `/pages/index/builder/builder`
				});
			},
			openBuilderDetails(id) {
				uni.navigateTo({
					url: `/pages/index/builder/details/details?id=${id}`
				});
			},
			openComboPage() {
				uni.navigateTo({
					url: '/pages/index/combo/combo'
				});
			},
			openConstructionPage() {
				uni.navigateTo({
					url: '/pages/index/construction/construction'
				});
			},
			openConstructionDetails(id) {
				uni.navigateTo({
					url: `/pages/index/construction/details/details?id=${id}`
				});
			}
		}
	};
</script>

<style lang="scss" scoped>
	page {
		background-color: #f5f5f5;
	}

	image {
		width: 100%;
	}

	::-webkit-scrollbar {
		display: none;
	}

	.content {
		padding-bottom: 112rpx;
	}

	.content-empty {
		padding-bottom: 112rpx;
	}

	.index_dialog {
		position: fixed;
		width: 100%;
		height: 100vh;
		z-index: 999;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		background-color: rgba(0, 0, 0, 0.5);

		.dialog_close {
			margin-top: 86rpx;
			width: 80rpx;
			height: 80rpx;
		}

		.dialog_banner {
			width: 542rpx;
			height: 724rpx;
		}
	}

	.serve {
		position: fixed;
		bottom: 132rpx;
		right: 20rpx;
		z-index: 999;

		.serve-image {
			width: 182rpx;
		}

		.serve-item {
			background: rgba(255, 255, 255, 0.8);
			border-radius: 12rpx;
			box-shadow: -4rpx 4rpx 4rpx 0rpx rgba(0, 0, 0, 0.15);
			padding-bottom: 40rpx;

			.header-more {
				padding: 20rpx;
			}

			.serve-close {
				width: 44rpx;
			}

			.serve-item-title {
				margin-left: 20rpx;
			}

			.serve-item-list {
				.serve-item-list {
					display: flex;
					padding: 0 46rpx;
					margin-top: 20rpx;

					.serve-image {
						width: 44rpx;
					}

					.serve-title {
						margin-left: 40rpx;
						font-size: 28rpx;
					}
				}
			}

			.serve-item-list:first-child {
				margin-top: 32rpx;
			}
		}
	}

	.menu-list {
		display: flex;
		padding: 40rpx 0;

		.menu-item {
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			flex-basis: 30%;

			.menu-text {
				font-size: 24rpx;
			}

			.menu-image {
				width: 80rpx;
			}
		}
	}

	.select {
		padding: 28rpx 40rpx 28rpx 40rpx;
		background-color: white;
		margin-top: 40rpx;

		.select-header {
			font-size: 28rpx;
			margin-left: 20rpx;
		}

		.more-text {
			font-size: 24rpx;
		}

		.more-icon {
			width: 8rpx;
			height: 8rpx;
			margin-left: 10rpx;
			border-left: 2rpx solid #333;
			border-top: 2rpx solid #333;
			transform: rotate(135deg);
		}

		.select-list {
			display: flex;
			overflow-x: scroll;
			overflow-y: hidden;

			.select-item {
				position: relative;
				width: 382rpx;
				height: 510rpx;
				margin-top: 20rpx;
				margin-left: 40rpx;

				.select-image {
					width: 382rpx;
					height: 510rpx;
				}

				.select-image image {
					width: 100%;
					height: 100%;
					border-radius: 16rpx;
				}

				.select-mark {
					position: absolute;
					background-color: rgba(0, 0, 0, 0.3);
					box-sizing: border-box;
					border-bottom-left-radius: 16rpx;
					border-bottom-right-radius: 16rpx;
					bottom: 0;
					width: 382rpx;
					padding: 12rpx 24rpx;
					line-height: 1.2em;

					.select-title {
						font-size: 24rpx;
						color: white;
					}

					.select-content {
						margin-top: 8rpx;
						font-size: 20rpx;
						color: rgba(255, 255, 255, 0.7);
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 2;
						overflow: hidden;
					}
				}
			}

			.select-item:first-child {
				margin-left: 0;
			}
		}
	}

	.select:first-child {
		margin-top: 0;
	}
</style>